package com.alibaba.otter.manager.biz.config.canal.dal;

import com.alibaba.otter.manager.biz.dto.CommonSearchDTO;
import com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Pageable;

/**
 * CanalDao: 数据操作接口
 * <p>
 * 这只是一个减少手工创建的模板文件
 * 可以任意添加方法和实现, 更改作者和重定义类名
 * <p/>@author Powered By Fluent Mybatis
 */
public interface CanalDao extends BaseMapper<CanalDO> {


    boolean checkUnique(CanalDO canalDO);


    long uniqueInsert(CanalDO canalDO);

    default CanalDO selectByName(String name) {

        QueryWrapper q = QueryWrapper.create().eq(CanalDO::getName, name);
        return selectOneByQuery(q);
    }


    default Page<CanalDO> canalPage(CommonSearchDTO searchVo, Pageable pageable) {

        QueryWrapper q = QueryWrapper.create().eq(CanalDO::getName, searchVo.getName(), StringUtils::isNotBlank);
        return paginate(pageable.getPageNumber(), pageable.getPageSize(), q);

    }
}
